﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WEEK12_上课演示
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindDataList();
            }
        }

        protected void BindDataList()
        {
            SqlConnection connection = SqlHelper.GetConnection();
            DataSet dataSet = SqlHelper.GetDataSetBySqlCommand("SELECT * FROM Student", connection);

            DataList1.DataSource = dataSet;
            DataList1.DataBind();
        }

        protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
        }

        protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
            var rowView = e.Item.DataItem as DataRowView;
            if (e.CommandName == "Buy")
            {
                //TextBox tempTextBox = e.Item.FindControl("txtStudentID") as TextBox;
                //string studentID = tempTextBox.Text;
                Response.Write("购买了" + rowView[0]);
            }
        }
    }
}